<?php 
	include 'db.php';
	$itemId = $_POST['targetItem'];
	//$isActive = $_POST['isActive'];
	
	$magDesc = $_POST['magDesc'];
	$phCode = $_POST['phCode'];
	$itemName = $_POST['itemName'];
	$itemDesc = $_POST['itemDesc'];
	$itemPrice = $_POST['itemPrice'];
	$wattage = $_POST['watts'];
	$halogenWatt = $_POST['chw'];
	$socket = $_POST['socket'];
	$beamInt = $_POST['binsten'];
	$beamAngle = $_POST['bangle'];
	$lifetime = $_POST['lifetime'];
	$dimmable = $_POST['dimmable'];
	$lumenOutput = $_POST['lumout'];
	$efficacy = $_POST['effi'];
	$unitsPerPack = $_POST['upp'];
	$colorRendering = $_POST['cri'];
	$colorTemp = $_POST['colorTemp'];
	$NC = $_POST['nc'];
	
	
	
	
	$err = NULL;
	
	if($_FILES["pimg_edit"]["name"]){
			$acceptfile = array('jpg','jpeg','png');
			$gettype = explode(".",$_FILES["pimg_edit"]["name"]);
			if(in_array($gettype[1],$acceptfile)){
					$target_path = "productimages/";	
					$target_path_ = $target_path . basename($_FILES['pimg_edit']['name']); 
					if(move_uploaded_file($_FILES['pimg_edit']['tmp_name'], $target_path_)) {
						$target_path = $target_path . basename( $_FILES['pimg_edit']['name']); 
					}else{
						$err = "Uploading file error";
					}
					
			}else{
				$err = "Invalid File Format";
			}			
	}else{
		$target_path = @$_POST['old_img'];
	}
	$target_path = ($target_path)? "'$target_path'" : 'NULL';
	$res = ($err)? $err : 'success'; 
	
	
	
	$sql = "UPDATE items SET magDesc='$magDesc', phCode='$phCode',itemName='$itemName', itemDesc='$itemDesc', itemPrice='$itemPrice', wattage='$wattage', halogenWatt='$halogenWatt', socket='$socket', beamInt='$beamInt', beamAngle='$beamAngle', lifetime='$lifetime', dimmable='$dimmable', lumenOutput='$lumenOutput', efficacy='$efficacy', unitsPerPack='$unitsPerPack', colorRendering='$colorRendering', colorTemp='$colorTemp', NC='$NC', image = $target_path WHERE itemId='$itemId'";
	
	
	@mysql_query($sql);	
	
	$categories = @$_POST['addcat'];
	$delall = mysql_query("DELETE FROM cat_items WHERE item_id = $itemId");
	foreach($categories as $val){
		mysql_query("INSERT INTO cat_items SET cat_id = $val, item_id = $itemId");
	}
	
	
	header("Location: led-master.php?mngr=prod&action=success");	

?>